Maybe you should try to do it with boost::spirit.